/* thread.h : dgnsc thread
 * Copyright (C) 2009-2010 drangon <drangon.zhou@gmail.com>
 * 2009-05
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef INCLUDED_DGNSC_THREAD_H
#define INCLUDED_DGNSC_THREAD_H

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

typedef void * dgn_thread_t;
typedef void (*dgn_thread_func_t)( dgn_thread_t th, void * arg );

// create and start the thread, if start failed, return NULL, arg not touch
dgn_thread_t dgn_thread_init( dgn_thread_func_t thfunc, void * arg, void * tag );
// wait the thread stop and destroy it, should not be call by the thread func !!
int dgn_thread_fini( dgn_thread_t thd );

// in dgn_thread_func_t, should check this flag and quit graceful if not running
int dgn_thread_is_running( dgn_thread_t thd );
int dgn_thread_signal_stop( dgn_thread_t thd );

// user data
void * dgn_thread_get_tag( dgn_thread_t thd );
void dgn_thread_set_tag( dgn_thread_t thd, void * tag );

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // INCLUDED_DGNSC_THREAD_H

